using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VCUTAUFTR
    {
        public DataRow Convert2CUTAUFTR(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryCUTAUFTR(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["CUMANDANT"] = " ".PadRight(2 ); 
         dwReturn["CUAUFTNR"] = " ".PadRight(11 ); 
         dwReturn["CUVORGANG"] = " ".PadRight(1 ); 
         dwReturn["CUKUNDNR"] = " ".PadRight(8 ); 
         dwReturn["CUKUNDNAME"] = " ".PadRight(25 ); 
         dwReturn["CUVB"] = " ".PadRight(3 ); 
         dwReturn["CUVG"] = " ".PadRight(3 ); 
         dwReturn["CUADRSL"] = " ".PadRight(8 ); 
         dwReturn["CUWAEHRSL"] = " ".PadRight(3 ); 
         dwReturn["CUZAHLBED"] = " ".PadRight(3 ); 
         dwReturn["CULIEFBED"] = " ".PadRight(3 ); 
         dwReturn["CULIEFKOMP"] = " ".PadRight(1 ); 
         dwReturn["CUVERSART"] = " ".PadRight(3 ); 
         dwReturn["CUSPED"] = " ".PadRight(3 ); 
         dwReturn["CULIEFDAT"] = " ".PadRight(8 ); 
         dwReturn["CUAEDAT"] = " ".PadRight(8 ); 
         dwReturn["CUKOLL"] = " ".PadRight(5 ); 
         dwReturn["CUART"] = " ".PadRight(24 ); 
         dwReturn["CUFARBE"] = " ".PadRight(10 ); 
         dwReturn["CUDOMPART"] = " ".PadRight(11 ); 
         dwReturn["CUPARTGL"] = " ".PadRight(3 ); 
         dwReturn["CUKONFKZ"] = " ".PadRight(1 ); 
         dwReturn["CUKETTELN"] = " ".PadRight(1 ); 
         dwReturn["CUZENSUR"] = " ".PadRight(1 ); 
         dwReturn["CUKDBEZ"] = " ".PadRight(30 ); 
         dwReturn["CUARTBEZ"] = " ".PadRight(30 ); 
         dwReturn["CULAENGE"] = " ".PadRight(6 ); 
         dwReturn["CUBREITE"] = " ".PadRight(5 ); 
         dwReturn["CUMEEH"] = " ".PadRight(3 ); 
         dwReturn["CUMEEHFKT"] = " ".PadRight(12 ); 
         dwReturn["CUVERPART"] = " ".PadRight(3 ); 
         dwReturn["CUAUFMART"] = " ".PadRight(2 ); 
         dwReturn["CULNAME1"] = " ".PadRight(25 ); 
         dwReturn["CULNAME2"] = " ".PadRight(25 ); 
         dwReturn["CULSTRASSE1"] = " ".PadRight(25 ); 
         dwReturn["CULLKZ"] = " ".PadRight(3 ); 
         dwReturn["CULPLZ"] = " ".PadRight(7 ); 
         dwReturn["CULORT"] = " ".PadRight(25 ); 
         dwReturn["CUBEM"] = " ".PadRight(65 ); 
         dwReturn["CUMAILKZ"] = " ".PadRight(1 ); 
         dwReturn["CULO"] = " ".PadRight(2 ); 
         dwReturn["CUFIXTERM"] = " ".PadRight(1 ); 
         dwReturn["CUFILLER1"] = " ".PadRight(28 ); 
         dwReturn["CUBEARBKZ"] = " ".PadRight(1 ); 
         dwReturn["CUWVTERM"] = " ".PadRight(8 ); 
         dwReturn["CUWVZEIT"] = " ".PadRight(4 ); 
         dwReturn["CUDKWA"] = " ".PadRight(14 ); 
         dwReturn["CUDARTVAR"] = " ".PadRight(22 ); 
         dwReturn["CUDZUSAETZE"] = " ".PadRight(40 ); 
         dwReturn["CUDFARBGRP"] = " ".PadRight(1 ); 
         dwReturn["CUPRAUFKRS"] = " ".PadRight(2 ); 
         dwReturn["CUPRAUFLFD"] = " ".PadRight(6 ); 
         dwReturn["CUPRAUFPOS"] = " ".PadRight(3 ); 
         dwReturn["CULIEFSCH"] = " ".PadRight(10 ); 
         dwReturn["CUTEILNR"] = " ".PadRight(2 ); 
         dwReturn["CUFEHLTEXT"] = " ".PadRight(30 ); 
         dwReturn["CUAENDZL"] = " ".PadRight(0 ); 
         dwReturn["CUMFILLER2"] = " ".PadRight(84 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapCUTAUFTR(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveCUTAUFTR(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryCUTAUFTR(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapCUTAUFTR(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertCUTAUFTR(dwLocal, ITXDBVERSION);
            }
            UpdateCUTAUFTR(dwLocal);
        }
        public void InsertCUTAUFTR(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO CUTAUFTR(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryCUTAUFTR(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM CUTAUFTR WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM CUTAUFTR  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "CUTAUFTR";
            Return = Result;
            return Return;
        }
        public void DeleteCUTAUFTR(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM CUTAUFTR   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateCUTAUFTR(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE CUTAUFTR SET "
                    +"CUMANDANT= :CUMANDANT,"
                    +"CUAUFTNR= :CUAUFTNR,"
                    +"CUVORGANG= :CUVORGANG,"
                    +"CUKUNDNR= :CUKUNDNR,"
                    +"CUKUNDNAME= :CUKUNDNAME,"
                    +"CUVB= :CUVB,"
                    +"CUVG= :CUVG,"
                    +"CUADRSL= :CUADRSL,"
                    +"CUWAEHRSL= :CUWAEHRSL,"
                    +"CUZAHLBED= :CUZAHLBED,"
                    +"CULIEFBED= :CULIEFBED,"
                    +"CULIEFKOMP= :CULIEFKOMP,"
                    +"CUVERSART= :CUVERSART,"
                    +"CUSPED= :CUSPED,"
                    +"CULIEFDAT= :CULIEFDAT,"
                    +"CUAEDAT= :CUAEDAT,"
                    +"CUKOLL= :CUKOLL,"
                    +"CUART= :CUART,"
                    +"CUFARBE= :CUFARBE,"
                    +"CUDOMPART= :CUDOMPART,"
                    +"CUPARTGL= :CUPARTGL,"
                    +"CUKONFKZ= :CUKONFKZ,"
                    +"CUKETTELN= :CUKETTELN,"
                    +"CUZENSUR= :CUZENSUR,"
                    +"CUKDBEZ= :CUKDBEZ,"
                    +"CUARTBEZ= :CUARTBEZ,"
                    +"CULAENGE= :CULAENGE,"
                    +"CUBREITE= :CUBREITE,"
                    +"CUMEEH= :CUMEEH,"
                    +"CUMEEHFKT= :CUMEEHFKT,"
                    +"CUVERPART= :CUVERPART,"
                    +"CUAUFMART= :CUAUFMART,"
                    +"CULNAME1= :CULNAME1,"
                    +"CULNAME2= :CULNAME2,"
                    +"CULSTRASSE1= :CULSTRASSE1,"
                    +"CULLKZ= :CULLKZ,"
                    +"CULPLZ= :CULPLZ,"
                    +"CULORT= :CULORT,"
                    +"CUBEM= :CUBEM,"
                    +"CUMAILKZ= :CUMAILKZ,"
                    +"CULO= :CULO,"
                    +"CUFIXTERM= :CUFIXTERM,"
                    +"CUFILLER1= :CUFILLER1,"
                    +"CUBEARBKZ= :CUBEARBKZ,"
                    +"CUWVTERM= :CUWVTERM,"
                    +"CUWVZEIT= :CUWVZEIT,"
                    +"CUDKWA= :CUDKWA,"
                    +"CUDARTVAR= :CUDARTVAR,"
                    +"CUDZUSAETZE= :CUDZUSAETZE,"
                    +"CUDFARBGRP= :CUDFARBGRP,"
                    +"CUPRAUFKRS= :CUPRAUFKRS,"
                    +"CUPRAUFLFD= :CUPRAUFLFD,"
                    +"CUPRAUFPOS= :CUPRAUFPOS,"
                    +"CULIEFSCH= :CULIEFSCH,"
                    +"CUTEILNR= :CUTEILNR,"
                    +"CUFEHLTEXT= :CUFEHLTEXT,"
                    +"CUAENDZL= :CUAENDZL,"
                    +"CUMFILLER2= :CUMFILLER2,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("CUMANDANT", OracleType.NVarChar).Value = dwData["CUMANDANT"].ToString(); 
          or1.Parameters.Add("CUAUFTNR", OracleType.NVarChar).Value = dwData["CUAUFTNR"].ToString(); 
          or1.Parameters.Add("CUVORGANG", OracleType.NVarChar).Value = dwData["CUVORGANG"].ToString(); 
          or1.Parameters.Add("CUKUNDNR", OracleType.NVarChar).Value = dwData["CUKUNDNR"].ToString(); 
          or1.Parameters.Add("CUKUNDNAME", OracleType.NVarChar).Value = dwData["CUKUNDNAME"].ToString(); 
          or1.Parameters.Add("CUVB", OracleType.NVarChar).Value = dwData["CUVB"].ToString(); 
          or1.Parameters.Add("CUVG", OracleType.NVarChar).Value = dwData["CUVG"].ToString(); 
          or1.Parameters.Add("CUADRSL", OracleType.NVarChar).Value = dwData["CUADRSL"].ToString(); 
          or1.Parameters.Add("CUWAEHRSL", OracleType.NVarChar).Value = dwData["CUWAEHRSL"].ToString(); 
          or1.Parameters.Add("CUZAHLBED", OracleType.NVarChar).Value = dwData["CUZAHLBED"].ToString(); 
          or1.Parameters.Add("CULIEFBED", OracleType.NVarChar).Value = dwData["CULIEFBED"].ToString(); 
          or1.Parameters.Add("CULIEFKOMP", OracleType.NVarChar).Value = dwData["CULIEFKOMP"].ToString(); 
          or1.Parameters.Add("CUVERSART", OracleType.NVarChar).Value = dwData["CUVERSART"].ToString(); 
          or1.Parameters.Add("CUSPED", OracleType.NVarChar).Value = dwData["CUSPED"].ToString(); 
          or1.Parameters.Add("CULIEFDAT", OracleType.NVarChar).Value = dwData["CULIEFDAT"].ToString(); 
          or1.Parameters.Add("CUAEDAT", OracleType.NVarChar).Value = dwData["CUAEDAT"].ToString(); 
          or1.Parameters.Add("CUKOLL", OracleType.NVarChar).Value = dwData["CUKOLL"].ToString(); 
          or1.Parameters.Add("CUART", OracleType.NVarChar).Value = dwData["CUART"].ToString(); 
          or1.Parameters.Add("CUFARBE", OracleType.NVarChar).Value = dwData["CUFARBE"].ToString(); 
          or1.Parameters.Add("CUDOMPART", OracleType.NVarChar).Value = dwData["CUDOMPART"].ToString(); 
          or1.Parameters.Add("CUPARTGL", OracleType.NVarChar).Value = dwData["CUPARTGL"].ToString(); 
          or1.Parameters.Add("CUKONFKZ", OracleType.NVarChar).Value = dwData["CUKONFKZ"].ToString(); 
          or1.Parameters.Add("CUKETTELN", OracleType.NVarChar).Value = dwData["CUKETTELN"].ToString(); 
          or1.Parameters.Add("CUZENSUR", OracleType.NVarChar).Value = dwData["CUZENSUR"].ToString(); 
          or1.Parameters.Add("CUKDBEZ", OracleType.NVarChar).Value = dwData["CUKDBEZ"].ToString(); 
          or1.Parameters.Add("CUARTBEZ", OracleType.NVarChar).Value = dwData["CUARTBEZ"].ToString(); 
          or1.Parameters.Add("CULAENGE", OracleType.NVarChar).Value = dwData["CULAENGE"].ToString(); 
          or1.Parameters.Add("CUBREITE", OracleType.NVarChar).Value = dwData["CUBREITE"].ToString(); 
          or1.Parameters.Add("CUMEEH", OracleType.NVarChar).Value = dwData["CUMEEH"].ToString(); 
          or1.Parameters.Add("CUMEEHFKT", OracleType.NVarChar).Value = dwData["CUMEEHFKT"].ToString(); 
          or1.Parameters.Add("CUVERPART", OracleType.NVarChar).Value = dwData["CUVERPART"].ToString(); 
          or1.Parameters.Add("CUAUFMART", OracleType.NVarChar).Value = dwData["CUAUFMART"].ToString(); 
          or1.Parameters.Add("CULNAME1", OracleType.NVarChar).Value = dwData["CULNAME1"].ToString(); 
          or1.Parameters.Add("CULNAME2", OracleType.NVarChar).Value = dwData["CULNAME2"].ToString(); 
          or1.Parameters.Add("CULSTRASSE1", OracleType.NVarChar).Value = dwData["CULSTRASSE1"].ToString(); 
          or1.Parameters.Add("CULLKZ", OracleType.NVarChar).Value = dwData["CULLKZ"].ToString(); 
          or1.Parameters.Add("CULPLZ", OracleType.NVarChar).Value = dwData["CULPLZ"].ToString(); 
          or1.Parameters.Add("CULORT", OracleType.NVarChar).Value = dwData["CULORT"].ToString(); 
          or1.Parameters.Add("CUBEM", OracleType.NVarChar).Value = dwData["CUBEM"].ToString(); 
          or1.Parameters.Add("CUMAILKZ", OracleType.NVarChar).Value = dwData["CUMAILKZ"].ToString(); 
          or1.Parameters.Add("CULO", OracleType.NVarChar).Value = dwData["CULO"].ToString(); 
          or1.Parameters.Add("CUFIXTERM", OracleType.NVarChar).Value = dwData["CUFIXTERM"].ToString(); 
          or1.Parameters.Add("CUFILLER1", OracleType.NVarChar).Value = dwData["CUFILLER1"].ToString(); 
          or1.Parameters.Add("CUBEARBKZ", OracleType.NVarChar).Value = dwData["CUBEARBKZ"].ToString(); 
          or1.Parameters.Add("CUWVTERM", OracleType.NVarChar).Value = dwData["CUWVTERM"].ToString(); 
          or1.Parameters.Add("CUWVZEIT", OracleType.NVarChar).Value = dwData["CUWVZEIT"].ToString(); 
          or1.Parameters.Add("CUDKWA", OracleType.NVarChar).Value = dwData["CUDKWA"].ToString(); 
          or1.Parameters.Add("CUDARTVAR", OracleType.NVarChar).Value = dwData["CUDARTVAR"].ToString(); 
          or1.Parameters.Add("CUDZUSAETZE", OracleType.NVarChar).Value = dwData["CUDZUSAETZE"].ToString(); 
          or1.Parameters.Add("CUDFARBGRP", OracleType.NVarChar).Value = dwData["CUDFARBGRP"].ToString(); 
          or1.Parameters.Add("CUPRAUFKRS", OracleType.NVarChar).Value = dwData["CUPRAUFKRS"].ToString(); 
          or1.Parameters.Add("CUPRAUFLFD", OracleType.NVarChar).Value = dwData["CUPRAUFLFD"].ToString(); 
          or1.Parameters.Add("CUPRAUFPOS", OracleType.NVarChar).Value = dwData["CUPRAUFPOS"].ToString(); 
          or1.Parameters.Add("CULIEFSCH", OracleType.NVarChar).Value = dwData["CULIEFSCH"].ToString(); 
          or1.Parameters.Add("CUTEILNR", OracleType.NVarChar).Value = dwData["CUTEILNR"].ToString(); 
          or1.Parameters.Add("CUFEHLTEXT", OracleType.NVarChar).Value = dwData["CUFEHLTEXT"].ToString(); 
          or1.Parameters.Add("CUAENDZL", OracleType.NVarChar).Value = dwData["CUAENDZL"].ToString(); 
          or1.Parameters.Add("CUMFILLER2", OracleType.NVarChar).Value = dwData["CUMFILLER2"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
